<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/include/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<%@ include file="/include/jquery.libs.jsp"%>
</head>
<body style="background: #f0f9fd;" class="easyui-layout">
<div data-options="region:'center'">
	<table id="dg_field" title="字段列表" class="easyui-datagrid"
		   data-options="fit:true,toolbar:'#toolbar',
			   			url:'${ctx}/${frameworkPath}/field/list?sort=FIELD_ID&&dir=asc&functionId=${param.functionId}',
			   			method:'POST',
			   			pagination:true,
			   			rownumbers:true,
			   			fitColumns:true,
			   			singleSelect:false,
			   			pageSize:30">
		<thead>
		<tr>
			<th data-options="field:'ck',checkbox:true"></th>
			<th field="id" width="20"><fmt:message key="field.id" />
			</th>
			<th field="code" width="50"><fmt:message key="field.code" />
			</th>
			<th field="name" width="50"><fmt:message key="field.name" />
			</th>
			<th field="type" width="50"><fmt:message key="field.type" />
			</th>
			<th field="creator" width="50"><fmt:message key="column.creator" />
			</th>
			<th field="created" width="50"><fmt:message key="column.created" />
			</th>
			<th field="order" width="50"><fmt:message key="column.order" />
			</th>
		</tr>
		</thead>
	</table>
</div>

<div id="toolbar" >
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'button-add',plain:true,size:'medium'"
	   onClick="createField();">添加</a>
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'button-edit',plain:true,size:'medium'"
	   onClick="editField();">修改</a>
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'button-delete',plain:true,size:'medium'"
	   onClick="deleteField();">删除</a>
</div>

<script type="text/javascript">

	var win_top = window.top;
	var mydialog = win_top.$('#dialog');

	function createField() {
		mydialog.dialog('refresh','${ctx}/${frameworkPath}/field/create?functionId=${param.functionId}')
				.dialog({title:'新建字段', width:700,top:100,onLoad:function(){return false;}});
		mydialog.dialog('open');
	};

	function editField() {
		var row = $('#dg_field').datagrid('getSelected');
		if (row) {
			mydialog.dialog('refresh','${ctx}/${frameworkPath}/field/edit?id='+ row.id).dialog({title:'编辑字段', width:700,top:100,onLoad:function(){return false;}});
			mydialog.dialog('open');
			return false;
		}
		else {
			$.messager.alert('<fmt:message key="message.title" />', '<fmt:message key="message.select.one.only" />', 'error');
			return;
		}
	};

	function deleteField() {
		var rows = $('#dg_field').datagrid('getSelections');
		if (rows.length <= 0) {
			win_top.$.messager.alert('<fmt:message key="message.title" />',
					'<fmt:message key="message.select.one.only" />',
					'error');
			return;
		}
		$.messager.confirm('<fmt:message key="message.title" />', '是否要删除选中的功能？',
				function(r) {
					if (r) {
						var idArray = new Array();
						for ( var i = 0; i < rows.length; i++) {
							idArray.push(rows[i].id);
						}
						$.ajax({
							type : 'POST',
							url : '${ctx}/${frameworkPath}/field/delete',
							traditional : true,
							data : {
								'ids' : idArray,
								_method:'delete'
							},
							success : function(data) {
								if(data.success) {
									$("#dg_field").datagrid('reload');
									$.messager.alert('<fmt:message key="message.title" />',
											'<fmt:message key="message.delete.successful" />', 'info');
								}
								else{
									$.messager.alert('<fmt:message key="message.title" />', '删除错误：' + data.error, 'error');
								}
							},
							error : function(XmlHttpRequest, textStatus, errorThrown) {
								$.messager.alert('<fmt:message key="message.title" />', '删除错误：' + XmlHttpRequest.status, 'error');
							}
						});
						return false;
					}
				});
	};
</script>
</body>
</html>